//
//  MYGuideCommonService.m
//  homeland
//
//  Created by Alawn on 13-10-24.
//  Copyright (c) 2013年 xzysun. All rights reserved.
//

#import "MYGuideCommonService.h"
#import "CommonWorkGuideEntity.h"
#import "WorkQueryCell.h"
#import "WorkQuerySelectEntity.h"
#import "StreetWorkEntity.h"
#import "StreetWorkGuideEntity.h"
#import "OrgListItem.h"
#import "StreetWorkGuideOrgEntity.h"
#import "StreetGuidDetailController.h"
#import "StreetGuideDetailWebViewController.h"

@implementation MYGuideCommonService
-(id)init
{
    self = [super init];
    if (self) {
        _dataItemName = @"StreetWorkGuideEntity";
        self.fastSearchType = -1;//初始化
    }
    return self;
}
-(void)loadDataWithKey:(NSString *)keyOrNil
{
    _currentPageNo = 1;//刷新或查询的时候将请求页码变为1
    if (self.dataList) {
        self.dataList = nil;
    }
    NSMutableDictionary *params = [NSMutableDictionary dictionary];

        //按街道筛选
    _dataItemName = @"StreetWorkGuideEntity";
    if (keyOrNil) {
        [params setValue:keyOrNil forKey:@"name"];
        [params setValue:keyOrNil forKey:@"respectiveIssue"];

    } else {
        [params setValue:nil forKey:@"name"];
        [params setValue:nil forKey:@"respectiveIssue"];

    }
    [self doHttpPost:SERVER_URL_SEARCH_GUIDE_ITEM_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo] parameters:params];
}

-(void)loadMoreDataWithKey:(NSString *)keyOrNil
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
        //按街道筛选
        _dataItemName = @"StreetWorkGuideEntity";
        if (keyOrNil) {
            [params setValue:keyOrNil forKey:@"name"];
            [params setValue:keyOrNil forKey:@"respectiveIssue"];
            
        } else {
            [params setValue:nil forKey:@"name"];
            [params setValue:nil forKey:@"respectiveIssue"];
            
        }
        [self doHttpPost:SERVER_URL_SEARCH_GUIDE_ITEM_LIST headers:nil path:[NSString stringWithFormat:@"/%d",_currentPageNo + 1] parameters:params];
}

-(void)configCell:(UITableViewCell *)cell atIndex:(NSIndexPath *)index
{
    
    WorkQueryCell *tempCell = (WorkQueryCell *)cell;
    
    StreetWorkGuideEntity *item = [self.dataList objectAtIndex:index.row];
    [self configInfoWithCommonGuidCell:tempCell withItem:item atIndex:index.row];
    
    
//    if ([self.dataItem isKindOfClass:[StreetWorkEntity class]] || self.fastSearchType == 0) {
//        //按街道筛选
//        StreetWorkGuideEntity *item = [self.dataList objectAtIndex:index.row];
//        [self configInfoWithCommonGuidCell:tempCell withItem:item atIndex:index.row];
//    } else if ([self.dataItem isKindOfClass:[OrgListItem class]] || self.fastSearchType == 1) {
//        //按部门筛选
//        StreetWorkGuideOrgEntity *item = [self.dataList objectAtIndex:index.row];
//        tempCell.mainInfoLabel.text = item.title;
//        tempCell.guidButton.tag = index.row;
//        if (self.delegate && [self.delegate respondsToSelector:@selector(guidCommonButtonAction:)]) {
//            [tempCell.guidButton addTarget:self.delegate action:@selector(guidCommonButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//        }
//    }
}

-(CGFloat)heightForCellAtRow:(NSIndexPath *)index
{
    return 64.0f;
}

-(ConfigableViewController *)getCellTargetViewControllerForName:(NSString *)className
{
    if ([self.dataItem isKindOfClass:[StreetWorkEntity class]] || self.fastSearchType == 0) {
        //按街道筛选
        StreetGuidDetailController *vc = [[StreetGuidDetailController alloc] initWithNibName:@"StreetGuidDetailController" bundle:nil];
        return vc;
    } else if ([self.dataItem isKindOfClass:[OrgListItem class]] || self.fastSearchType == 1) {
        //按部门筛选
        StreetGuideDetailWebViewController *vc = [[StreetGuideDetailWebViewController alloc] initWithNibName:@"StreetGuideDetailWebViewController" bundle:nil];
        return vc;
    }
    return nil;
}
@end
